var vm_shenhelist_shenhe = new Vue({
    el : "#shenhelist_shenhe",
    data : {
        deptid : $("#deptid").val(),		// 单位ID
        olddeptid : $("#olddeptid").val(),		// 单位ID
        userid : $("#userid").val(),
        username : $("#username").val(),

        shenhelist : [],//
        renwuid : '',//
        shenhe : {},//
        biandong : {},//变动表
        shenhejilulist : [],

        //查询用字段
        shenhezhuangtai : '99',//0待审核 1通过 2未通过
        jigoumingcheng : '',
        zhuanjiaxingming : '',
        renwuxiafashijian1 : '',
        renwuxiafashijian2 : '',
        renwuwanchengshijian1 : '',
        renwuwanchengshijian2 : '',

        zhipaidept:'',
        shenhezhipaiid:'',
        shenhezhipaimingcheng:'',

        Xiafa:{
            id:'',//下发
            shiwuid:'',
            deptid:'',
        },

        shenheyijian : '',//审核意见

        pageindex : 1,		// 查询分页初始化页
        pagesize : 10,		// 查询分页初始化页面大小
        pageCount : 0,		// 总页数
        recordCount : 0,	// 总记录数
        targetpage : '', 	// 目标页

    },
    created : function(){
        var _this = this;

        _this.bindShenheList();

    },
    watch : {
        //监控分页情况，刷新列表
        pageindex : function(){
            this.bindShenheList();
        },

        pagesize : function(){
            //
            this.bindShenheList();
        },

        shenhezhuangtai : function(){
            this.bindShenheList();
        }
    },
    methods : {

        // 根据单位ID查询下级单位
        bindShenheList : function(){
            var _this = this;

            var shenhe_layer = layer.open({type:3});
            $.post('/system/renwu/findzhuanlishenhelist', {
                deptid : _this.deptid,
                shenhezhuangtai : _this.shenhezhuangtai,
                jigoumingcheng : _this.jigoumingcheng,
                zhuanjiaxingming : _this.zhuanjiaxingming,
                renwuxiafashijian1 : _this.renwuxiafashijian1,
                renwuxiafashijian2 : _this.renwuxiafashijian2,
                renwuwanchengshijian1 : _this.renwuwanchengshijian1,
                renwuwanchengshijian2 : _this.renwuwanchengshijian2,
                pageindex : _this.pageindex,
                pagesize : _this.pagesize,
                rdm : Math.random()
            },function(ppData) {
                layer.close(shenhe_layer);

                if (ppData != null) {
                    var data = ppData.resultContent;
                    _this.shenhelist = data.shenhelist;

                    var pageInfo = data.PageInfo;
                    _this.pageindex = pageInfo.pageIndex;
                    _this.pageCount = pageInfo.pageCount;
                    _this.recordCount = pageInfo.recordCount;
                    _this.targetpage = '';
                }
            },"json");
        },

        ShowShenheModal:function(shenheitem){
            var _this = this;
            _this.shenhe = shenheitem;
            $("[name='shenhezhipai']").hide()
            $("#zhuanru").attr("colSpan",3);
            $("#myModalLabel").html("专家转隶情况审核");
            $("#modal-dialog").attr("style","width:1200px;");
            $("#shenheModal").modal();
            if(_this.olddeptid=="000"&&shenheitem.zhuanzhidanwei==null){
                $("#zhuanru").attr("colSpan",1);
                $("[name='shenhezhipai']").show()
                $("#shenhezhipai").html("");
                _this.zhipaidept=''
                _this.shenhezhipaiid=''
                _this.shenhezhipaimingcheng=''
            }else {
                $("#shenhezhipai").append("<option value='" + shenheitem.zhuanzhidanwei + "' >" + shenheitem.zhuanzhidanweimingcheng + "</option>");
            }
        },

        //未完成
        Shenhe:function(ppShenhejieguo,ppIsRenling){
            var _this = this;
            _this.shenhezhipaiid=$("#shenhezhipai").val()!=null?$("#shenhezhipai").val():''
            _this.shenhezhipaimingcheng=$("#shenhezhipai").find("option:selected").text()?$("#shenhezhipai").find("option:selected").text():''
            if (_this.checkInputData(ppShenhejieguo)) {
                var biandong_layer = layer.open({type: 3});
                $.post('/system/renwu/shenhe_zhuanli', {
                    id:_this.shenhe.id,
                    shiwuid: _this.shenhe.shiwuid,
                    renwuid: _this.shenhe.renwuid,
                    shenherenid:_this.userid,
                    shenheren:_this.username,
                    shifoutongguo:ppShenhejieguo,
                    shenheyijian:_this.shenheyijian,
                    deptid:_this.deptid,
                    isrenling : ppIsRenling,
                    zhuanzhidanweiid: _this.shenhezhipaiid,
                    zhuanzhidanweimingcheng: _this.shenhezhipaimingcheng,
                    rdm: Math.random()
                }, function (ppData) {
                    layer.close(biandong_layer);
                    if (ppData != null) {

                        if (ppData.result == "1") {
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "审核成功!",
                            });

                            _this.refresh();
                            $("#shenheModal").modal('hide');

                        } else {
                            layer.alert(ppData.message);
                        }
                    }
                }, "json");
            }
        },

        //检查项目数据
        checkInputData : function(ppShenhejieguo) {
            if (ppShenhejieguo==2){

                if (!$.trim(this.shenheyijian)) {
                    layer.alert("请填写审核意见！");
                    return false;
                }
            }

            return true;
        },

        Export:function () {
            var _this = this
            location.href = "/export/renshiguanxizhuanchushenhe?deptid="+this.deptid
                +"&shenhezhuangtai="+_this.shenhezhuangtai
                +"&jigoumingcheng="+_this.jigoumingcheng
                +"&zhuanjiaxingming="+_this.zhuanjiaxingming
                +"&renwuxiafashijian1="+_this.renwuxiafashijian1
                +"&renwuxiafashijian2="+_this.renwuxiafashijian2
                +"&renwuwanchengshijian1="+_this.renwuwanchengshijian1
                +"&renwuwanchengshijian2="+_this.renwuwanchengshijian2

        },

        refresh:function(){
            var _this = this;

            _this.bindShenheList();
        },

        toDetail : function(ppBiandongitem){
            this.biandong =ppBiandongitem;
            $("#myModalLabel3").html("专家转隶详情");
            $("#biandongdetailModal").modal();
        },

        showShenhejiluModel:function(ppShiwuId){
            var _this = this;

            $("#shenhejiluModalLabel").html("审核进度");
            $("#shenhejiluModal").modal();

            _this.bindShenhejilu(ppShiwuId);
        },

        bindShenhejilu:function(ppShiwuId){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/renwu/findshenhejilu', {
                shiwuid : ppShiwuId,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if (ppData != null) {
                    var data = ppData;
                    _this.shenhejilulist = data.resultContent;
                }
            },"json");
        },
        toXiafa:function (shenheitem) {
            var _this = this;
            $("#zhipai").html("");
            _this.Xiafa.id = shenheitem.id
            _this.Xiafa.shiwuid = shenheitem.shiwuid
            _this.Xiafa.deptid = shenheitem.deptid
            if(shenheitem.zhuanzhidanwei==null||shenheitem.zhuanzhidanwei=='') {
                $("#zhipai").html("");
            }else {
                $("#zhipai").append("<option value='" + shenheitem.zhuanzhidanwei + "' >" + shenheitem.zhuanzhidanweimingcheng + "</option>");
                $('[name="search"]').hide()
            }
            _this.zhipaidept=''
            $("#myModalLabel5").html("指派单位");
            $("#XiafaModal").modal();
        },
        deptsearch:function () {
            var _this = this
            $.post('/system/deptdetail/deptsearch', {
                jigoumingcheng: _this.zhipaidept,
                deptid:_this.olddeptid,
                rdm: Math.random()
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        $("#zhipai").html("");
                        var deptlist = ppData.resultContent;
                        for (var i = 0; i < deptlist.length; i++) {
                            $("#zhipai").append("<option value='" + deptlist[i].id + "' >" + deptlist[i].jigoumingcheng + "</option>");
                        }
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        shenhedeptsearch:function () {
            var _this = this
            $.post('/system/deptdetail/deptsearch', {
                jigoumingcheng: _this.zhipaidept,
                deptid:_this.olddeptid,
                rdm: Math.random()
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        $("#shenhezhipai").html("");
                        var deptlist = ppData.resultContent;
                        for (var i = 0; i < deptlist.length; i++) {
                            $("#shenhezhipai").append("<option value='" + deptlist[i].id + "' >" + deptlist[i].jigoumingcheng + "</option>");
                        }
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        xiapai:function () {
            var _this = this
            $.post('/system/renwu/xiapai', {
                id: _this.Xiafa.id,
                shiwuid: _this.Xiafa.shiwuid,
                deptid: _this.deptid,
                xiapaidanweiid: $("#zhipai").val(),
                rdm: Math.random()
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        layer.open({
                            time: 1000,
                            btn: [],
                            content: ppData.resultContent,
                        });
                        $("#XiafaModal").modal("hide");
                        _this.bindShenheList()
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        Jieshou:function (shenheitem,shifoutongguo) {
            var _this = this
            $.post('/system/renwu/jieshou', {
                id: shenheitem.id,
                shiwuid: shenheitem.shiwuid,
                renwuid: shenheitem.renwuid,
                shenherenid: _this.userid,
                shenheren: _this.username,
                deptid: _this.deptid,
                shifoutongguo: shifoutongguo,
                rdm: Math.random()
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        layer.open({
                            time: 1000,
                            btn: [],
                            content: ppData.resultContent,
                        });
                        _this.bindShenheList()
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        getDate_chaxun:function(){
            var _this = this;

            _this.renwuxiafashijian1=$("#renwuxiafashijian1_chaxun").val();
            _this.renwuxiafashijian2=$("#renwuxiafashijian2_chaxun").val();
            _this.renwuwanchengshijian1=$("#renwuwanchengshijian1_chaxun").val();
            _this.renwuwanchengshijian2=$("#renwuwanchengshijian2_chaxun").val();
        },

        reset:function(){
            var _this = this;
            _this.shenhezhuangtai = '99';
            _this.jigoumingcheng = "";
            _this.zhuanjiaxingming = "";
            _this.renwuxiafashijian1 = "";
            _this.renwuxiafashijian2 = "";
            _this.renwuwanchengshijian1 = "";
            _this.renwuwanchengshijian2 = "";
            _this.bindShenheList()
        },

        //首页
        firstPage : function(){
            this.pageindex = 1;
        },
        //尾页
        lastPage : function(){
            this.pageindex = this.pageCount;
        },
        //上一页
        prePage : function(){
            var prePage = ((this.pageindex -1) <= 0) ? 1 : (this.pageindex -1);
            this.pageindex = prePage;
        },
        //下一页
        nextPage : function(){
            var nextPage = ((this.pageindex +1) >= this.pageCount) ? this.pageCount : (this.pageindex +1);
            this.pageindex = nextPage;
        },
        //跳到目标页
        targetPage : function() {
            if( this.targetpage != '' && this.targetpage <= this.pageCount && this.targetpage > 0){
                this.pageindex = this.targetpage;
                this.targetpage = '';
            }
        },
    },
});